package metier;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import persistence.dao.RoleDAO;
import persistence.model.Affectation;
import persistence.model.Role;
import presentation.beans.AffectationBean;
import presentation.beans.RoleBean;

/**
 * @author Ben
 * 
 */
public class RoleAction {
	
	private RoleDAO roleDAO = RoleDAO.getInstance();

	public static Role beanToRole(RoleBean roleBean) {
		Role role = new Role();
		role.setIdRole(roleBean.getIdRole());
		role.setNomRole(roleBean.getNomRole());
		role.setTypeRole(roleBean.getTypeRole());
//		List<AffectationBean> affectations = new ArrayList<AffectationBean>(roleBean.getAffectation());
//		Set<Affectation> affectation = new HashSet<Affectation>();
//		for (int i = 0; i < affectations.size(); i++)
//			affectation.add(AffectationAction.beanToAffectation(affectations.get(i)));
//		role.setAffectation(affectation);
		return role;
	}

	public static RoleBean roleToBean(Role role) {
		RoleBean roleBean = new RoleBean();
		roleBean.setIdRole(role.getIdRole());
		roleBean.setNomRole(role.getNomRole());
		roleBean.setTypeRole(role.getTypeRole());
//		List<AffectationBean> affectation = new ArrayList<AffectationBean>();
//		List<Affectation> affectations = new ArrayList<Affectation>(role.getAffectation());
//		for (int i = 0; i < affectations.size(); i++)
//			affectation.add(AffectationAction.affectationToBean(affectations.get(i)));
//		roleBean.setAffectation(affectation);
		return roleBean;
	}
	
	public RoleBean getCP(){
		RoleBean roleBean = new RoleBean();
		roleBean = roleToBean(roleDAO.getCP());
		return roleBean;
	}
	
	public RoleBean getConsultant(){
		RoleBean roleBean = new RoleBean();
		roleBean = roleToBean(roleDAO.getConsultant());
		return roleBean;
	}

}
